package br.com.felix.fwt.ui.javascript;

import java.io.Serializable;


/**
 * This class is used to associate scripts to events.
 * Its implemented in a different manner than the common 'addXXXListener' to try to simplify things. 
 * 
 * @see br.com.felix.fwt.ui.javascript.Event
 */
public class JavascriptListener implements Serializable{
	

	private static final long serialVersionUID = -2664375774098051289L;
	/** The script to be run. */
	private String script;
	
	/**
	 * Instantiates a new javascript listener.
	 * 
	 * @param event the event the will dispatch the scripts.
	 * @param js the scripts that will be run when the event is dispathed.
	 */
	public JavascriptListener(Event event, Javascript ... js ){
		script = event.toString()+"=\"";
		for(Javascript j: js){
			script += j.script();
		}
		script += "\"";
	}
	
	/**
	 * This method returns the Javascript code generated by this class.
	 * 
	 * @return the HTML code generated. Something like 'event="javascriptcode1;javascriptcode2;'
	 */
	public String script(){
		return script;
	}
	
	/**
	 * @see #script()
	 */
	@Override
	public String toString(){
		return script;
	}
}
